//
//  CourseMainCollectionViewCell.m
//  Arts1
//
//  Created by 孤星晨宇 on 15/9/20.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "CourseMainCollectionViewCell.h"
#import <UIImageView+WebCache.h>

#import "AllHeader.h"


@implementation CourseMainCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {

        UIView *whiteView = [[UIView alloc] initWithFrame:self.bounds];
        whiteView.backgroundColor = [UIColor whiteColor];
        // view 切成圆角的时候，不需要改动layer层的masksToBounds属性
        whiteView.layer.cornerRadius = 4;
        
        _mainImageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.height * 16 / 9, self.bounds.size.height)];
//        _mainImageview.image = [UIImage imageNamed:@"8.jpeg"];
        _mainImageview.backgroundColor = kRandomColor;
        [UIView viewRediusForTopAndBottomForLeft:_mainImageview withRedius:4];
        [_mainImageview setContentMode:(UIViewContentModeScaleAspectFill)];
        [whiteView addSubview:_mainImageview];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_mainImageview.width + 12, 10 , whiteView.width - _mainImageview.width - 20, 15)];
        _titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:12];
        _titleLabel.textColor = kCustomColor(40, 40, 50, 1);
//        _titleLabel.text = @"彩铅绘制";
        [whiteView addSubview:_titleLabel];
        
        _subtitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_mainImageview.width + 12, _titleLabel.bottom + 1 , whiteView.width - _mainImageview.width - 20, 15)];
        _subtitleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:11];
        _subtitleLabel.textColor = kCustomColor(80, 80, 90, 1);
//        _subtitleLabel.text = @"张喑";
        [whiteView addSubview: _subtitleLabel];
        

        
        UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(_mainImageview.right, 65, self.size.width - _mainImageview.size.width, 0.5)];
        lineView.backgroundColor = kCustomColor(150, 150, 150, 0.5);
        [whiteView addSubview:lineView];
        
        _viewNumImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_mainImageview.right + 12, lineView.bottom + 5, 15, 12)];
        _viewNumImageView.image = [UIImage imageNamed:@"ViewNum"];
        [whiteView addSubview:_viewNumImageView];
        
        _viewsLabel = [[UILabel alloc] initWithFrame:CGRectMake(_viewNumImageView.right + 2,_viewNumImageView.top, 30 , 11 )];
        _viewsLabel.font = [UIFont boldSystemFontOfSize:11];
        _viewsLabel.textColor = kCustomColor(180, 180, 180, 1);
//        _viewsLabel.text = @"浏览";
        [whiteView addSubview: _viewsLabel];
        
        _goodNumImageView = [[UIImageView alloc] initWithFrame:CGRectMake(_viewsLabel.right + 5, _viewsLabel.top, 15, 12)];
        _goodNumImageView.alpha = 0.8;
        _goodNumImageView.image = [UIImage imageNamed:@"tabGoodButton"];
        [whiteView addSubview:_goodNumImageView];
        
        _goodLabel = [[UILabel alloc] initWithFrame:CGRectMake(_goodNumImageView.right + 2, _goodNumImageView.top ,30, 11 )];
        _goodLabel.font = [UIFont boldSystemFontOfSize:11];
        _goodLabel.textColor = kCustomColor(180, 180, 180, 1);
//        _goodLabel.text = @"点赞";
        [whiteView addSubview: _goodLabel];
        
        
        _payLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.width - 60, lineView.bottom + 5 ,50 , 12 )];
        _payLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
        _payLabel.textColor = kCustomColor(180, 180, 180, 1);
        [_payLabel setTextAlignment:(NSTextAlignmentRight)];
        //        _payLabel.text = @"价格";
        [whiteView addSubview: _payLabel];
        
        
        
        _circle = [[UIView alloc] initWithFrame:CGRectMake(whiteView.width - 20 , 40, 8, 8)];

        _circle.layer.cornerRadius = 4.0;  //设置layer圆角半径
        _circle.layer.borderWidth = 1.0;
        _circle.layer.borderColor = kRandomColor.CGColor;
//        [whiteView addSubview:_circle];
        
        
        [UIView viewShadowColor:whiteView];
        [self.contentView addSubview:whiteView];
    
    }
    return self;
}


- (void)setCourse:(CourseModel *)course{
    _course = course;
    [_mainImageview sd_setImageWithURL:[NSURL URLWithString:_course.photo] placeholderImage:nil options:SDWebImageRetryFailed | SDWebImageLowPriority];
    _titleLabel.text = _course.title;
//    _payLabel.text = [NSString stringWithFormat:@"￥%@",_course.price];
    _viewsLabel.text = [NSString stringWithFormat:@"%@",_course.views];
    _goodLabel.text = [NSString stringWithFormat:@"%@",_course.good];
    
    // 课程老师
    if (_course.teacher == NULL) {
        _subtitleLabel.text = [NSString stringWithFormat:@"作者:未知"];
    } else{
        _subtitleLabel.text = [NSString stringWithFormat:@"作者:%@",_course.teacher];
    }
    
    //  点赞数
    if ([_course.price  isEqual: @"0.00"]) {
        _payLabel.alpha = 0;
    }else{
        _payLabel.text = [NSString stringWithFormat:@"￥%@",_course.price];
    }
    
}












@end
